/*************************************************
Author: will
Date: 4/18/2013
Description:
Notes: 
*************************************************/

#ifndef __apptencentapi_h__
#define __apptencentapi_h__

#include "CTSoBase.h"
#include "CTMsgBase.h"
#include "CTCodeMySQL.h"
#include "commmsg.h"
#include "commerrno.h"
#include "curl/curl.h"

using namespace CTLib;

class CAppTencentApi : public CTSoAppInf
{
public:
    CAppTencentApi();
    virtual ~CAppTencentApi();

    virtual int Init(void *);
    virtual int Do(const CEnpNetHead& stHead, const char* pszReqBuf, int iReqLen,
        char* pszAnsBuf, int iAnsBufLen, int& iAnsLen);
    virtual int Exit();

private:
    CURL* m_pstCurlHandle;

    static CAppTencentApi* m_pstApiCtrl;

    int InitCurl();
    int FreeCurl();

    static size_t RecvPacket(char *ptr, size_t size, size_t nmemb, void *userdata);

private:
    CTMsgHead m_stMsgHead;
    CReqTencentApi m_stReqApi;
    CAnsTencentApi m_stAnsApi;
    CTCodeStream m_stCodeStream;
    char m_szHttpReqEncodeBuf[40960];
    char m_szSig[50];
    char m_szRecvPacketBuf[204800];
    int  m_iRecvPacketLen; 

    int InitReq(const char* pszReqBuf, int iReqLen);
    int DealReq();
    int SendAns(int iResult, char* pszAnsBuf, int iAnsBufLen, int& iAnsLen);
    const char* UrlEncode(const char* szStr);
    const char* GetSig();
    bool IsApiUseGet ();
    bool IsApiUseHttps ();
};


#endif // __apptencentapi_h__

